 

import os
def foldersize(dirname):
    filesize=0
    filename=""
    #取当前目录下的所有文件大小
    files=os.listdir(dirname)
    for file1  in files:
        #print(file1)
        filename=dirname +'\\'+file1
        if os.path.isfile(filename):
            filesize=filesize+os.path.getsize(filename)
        if os.path.isdir(filename):
            filesize=filesize+foldersize(filename)
    return filesize


filesize=foldersize('D:\\file')
print(filesize)
